<template>
  <CommonPageByDevice
    navTitle="云喇叭管理"
    searchTitle="搜索设备名称、编号"
    searchType="device"
    :searchParams="{ deviceType: 1 }"
	:bottomBtnTitle="ak.ent.has('ENT_DEVICE_SPEAKER_ADD') ? '绑定设备' : null "
    @bottomBtnClickFunc="bottomBtnClickFunc"
    :reqTableDataFunc="reqTableDataFunc"
    ref="commonPageByDeviceRef"
  >
  </CommonPageByDevice>
  <JSinglePopup ref="bindPopup" :list="codeBind" />
</template>

<script setup>
import { reactive, ref } from 'vue'
import { onReachBottom, onUnload } from '@dcloudio/uni-app'
import emit from '@/commons/utils/emit.js'
import infoBox from '@/commons/utils/infoBox.js'
import CommonPageByDevice from '../commons/CommonPageByDevice.vue'
import { reqLoad, API_URL_SYS_DEVICE_LIST } from '@/http/apiManager.js'
import go from '@/commons/utils/go.js'
import DeviceCommonsRender from '@/pages/list/render/DeviceCommonsRender.vue'
import ak from '@/commons/utils/ak.js'

uni.$on(emit.ENAME_REF_SPEAKER_LIST, (data) => {
  commonPageByDeviceRef.value.refTable(true)
})
const commonPageByDeviceRef = ref(null)
const reqTableDataFunc = (params) => {
  params.deviceType = 1 // 1-云喇叭, 2-云打印, 3-扫码pos, 4-智能pos, 5-收银插件
  return reqLoad.list(API_URL_SYS_DEVICE_LIST, params)
}
const bindPopup = ref(null)
function bottomBtnClickFunc() {
  bindPopup.value.open()
}

const codeBind = reactive([
  {
    label: '扫码绑定',
    value: 'scanCode',
    fun: () => {
      uni.scanCode({
        success: ({ result }) => {
          go.to('PAGES_APP_HORN_BIND', { deviceNo: result })
        },
        fail: (err) => {
          
        },
      })
    },
  },
  {
    label: '手动绑定',
    value: 'handBind',
    fun: () => {
      go.to('PAGES_APP_HORN_BIND')
    },
  },
])
onUnload(() => uni.$off(emit.ENAME_REF_SPEAKER_LIST))
onReachBottom(() => {})
</script>

<style lang="scss" scoped></style>
